<template>
  <div class="good-info-warp">
    <div class="good-info">
      <div
        class="good-info-path"
      >首页 > 手机 > HUAWEI nova系列 > HUAWEI nova 6 5G双模全网通 8GB+128GB 麒麟990芯片 前置3200万像素（亮黑色）</div>
      <div class="good-info-detail">
        <div class="left-img">
          <img :src="currentInfo.bigImages" style="display: block;" />
        </div>
        <div class="right-attrs">
          <div class="right-attrs-header">{{currentInfo.speName}}</div>
          <div class="right-attrs-price">
            <div class="right-attrs-price-item">
              <div class="right-attrs-price-label">价&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;格</div>
              <div class="right-attrs-price-vaule">
                <i style="font-size: 14px;">¥</i>
                {{currentInfo.price}}
              </div>
            </div>
          </div>
          <div class="right-attrs-item">
            <span class="right-attrs-item-label">选择颜色</span>
            <div class="color-type-warp">
              <template v-for="(item, i) in goodsInfo">
                <span
                  class="color-type"
                  :class="i == index ? 'select' : ''"
                  :key="i"
                  @click="changeType(i)"
                >
                  <img class="color-type-img" :src="item.bigImages" alt />
                  <span class="color-type-text">{{item.speName}}</span>
                </span>
              </template>
            </div>
          </div>
          <div class="right-attrs-item">
            <span class="right-attrs-item-label">库存</span>
            <div class="color-type-warp">{{currentInfo.stock}}</div>
          </div>
          <div class="right-attrs-btn-warp">
            <div class="input-warp">
              <input type="text" v-model="num" />
              <div class="input-contrl">
                <div class="c" @click="addNum">+</div>
                <div class="c" @click="deNum">-</div>
              </div>
            </div>
            <div class="btn-join-car btn">加入购物车</div>
            <div class="btn-shop btn" @click="goBuy">立即下单</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      num: 1,
      index: 0
    };
  },
  props: {
    goodInfo: Object,
    goodsInfo: Object,
    poster: String
  },
  computed: {
    currentInfo() {
      if (Array.isArray(this.goodsInfo) && this.goodsInfo.length > 0) {
        return this.goodsInfo[this.index];
      }
      return {};
    }
  },
  methods: {
    addNum() {
      this.num++;
    },
    deNum() {
      this.num--;
    },
    changeType(index) {
      this.index = index;
      console.log(this.goodsInfo[index]);
    },
    goBuy() {
      this.$router.push({
        name: 'buy',
        query: {
          projectId: this.$route.query.projectId,
          goodsProId: this.currentInfo.goodsProId,
          num: this.num
        }
      });
    }
  },
  mounted() {
    console.log(this.goodsInfo);
  }
};
</script>

<style lang="less" scoped>
  .good-info-warp {
    display: flex;
    justify-content: center;
    .good-info {
      width: 1200px;

      .good-info-path {
        color: #666;
        font-size: 12px;
        margin-top: 10px;
      }

      .good-info-detail {
        display: flex;
        justify-content: space-between;
        margin-top: 15px;

        .right-attrs {
          flex: 1;

          .right-attrs-item {
            display: flex;
            margin-top: 16px;
            flex-wrap: wrap;

            .right-attrs-item-label {
              line-height: 40px;
              width: 85px;
              color: #3a3a3a;
              font-size: 12px;
              text-align: center;
            }
            .color-type-warp {
              display: flex;
              align-items: center;
              font-size: 12px;

              .color-type {
                cursor: pointer;
                display: flex;
                width: 98px;
                height: 40px;
                justify-content: space-around;
                border: 1px solid #a4a4a4;
                align-items: center;
                border-radius: 2px;
                margin-right: 10px;

                &.select {
                  border: 1px solid #ca141d;
                }
              }

              .color-type-img {
                width: 30px;
                height: 30px;
              }

              .color-type-text {
                height: 34px;
                min-width: 0;
                max-width: 86px;
                color: #3a3a3a;
                font-size: 12px;
                display: flex;
                align-items: center;
              }
            }
          }
        }

        .right-attrs-header {
          font-size: 21px;
          overflow: hidden;
          margin-bottom: 10px;
        }

        .right-attrs-price {
          background: #f5f5f5;
          padding-top: 14px;
          padding-bottom: 3px;

          .right-attrs-price-item {
            display: flex;

            .right-attrs-price-label {
              font-size: 12px;
              width: 85px;
              text-indent: 10px;
              line-height: 30px;
              color: #3a3a3a;
              text-align: center;
            }

            .right-attrs-price-vaule {
              color: #ca141d;
              padding-right: 3px;
              font-size: 24px;
            }
          }
        }
      }
    }
  }

  .input-warp {
    width: 65px;
    height: 43px;
    display: flex;
    border: 1px solid #e2e2e2;
    input {
      width: 42px;
      height: 44px;
      border-left: 0;
      border-top: 0;
      border-bottom: 0;
      text-align: center;
    }
    .input-contrl {
      .c {
        cursor: pointer;
        width: 21px;
        height: 21px;
        border-bottom: 1px solid #e2e2e2;
        display: flex;
        align-items: center;
        justify-content: center;
      }
    }
  }
  .right-attrs-btn-warp {
    display: flex;
    margin-top: 20px;

    .btn-join-car {
      display: block;
      background: #fc600c;
      width: 172px;
      height: 46px;
      font-size: 18px;
      line-height: 46px;
      text-align: center;
      color: #fff;
      border-radius: 2px;
      border: 0;
      cursor: pointer;
      margin-right: 10px;
      margin-left: 10px;
    }
    .btn-shop {
      display: block;
      background: #ca151d;
      width: 172px;
      height: 46px;
      font-size: 18px;
      line-height: 46px;
      text-align: center;
      color: #fff;
      border-radius: 2px;
      border: 0;
      cursor: pointer;
      margin-right: 10px;
    }
  }
  .btn {
    width: 172px;
    height: 64px;
  }
  .left-img {
    width: 450px;
    height: 450px;

    img {
      width: 100%;
    }
  }
</style>